﻿using Swifter.RW;
#if UNITY
using UnityEngine;
#else
using System.Numerics;
#endif

namespace SwifterJson
{
    public class Vector2Interface : IValueInterface<Vector2>
    {
        public Vector2 ReadValue(IValueReader valueReader)
        {
            var str = valueReader.ReadString();
            return Parse2Vec2(str);
        }

        public void WriteValue(IValueWriter valueWriter, Vector2 value)
        {
            var str = string.Format("{0},{1}", value.X, value.Y);
            valueWriter.WriteString(str);
        }

        public static Vector2 Parse2Vec2(string str)
        {
            var s = str.Split(',');
            return new Vector2(float.Parse(s[0]), float.Parse(s[1]));
        }
    }

    public class Vector2InterfaceMaper : IValueInterfaceMaper
    {
        public IValueInterface<Vector2> TryMap<Vector2>()
        {
            return new Vector2Interface() as IValueInterface<Vector2>;
        }
    }
}
